// mircoApp/agentShop/agentShop_manage/agentShop_manage.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    infoData: {
      status: "0"
    },
    goodsList: [],
    posterShow: false,
    defaultImg: "",

    isLoadMore: true,
    page: 1,
    total_page: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  toSetting(){
    wx.navigateTo({
      url: '/mircoApp/agentShop/agentShop_setting/agentShop_setting',
    })
  },
  toGood(e) {
    let {
      item
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: '/packageA/detail_v2/detail_v2?id=' + item.id,
    })
  },
  async getData() {
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.agent-shop.frontend.agent.manage"),
    })
    if (!data.result) return app.tips(data.msg);
    if (data.data.status == 0) {
      this.getGood();
    }
    this.setData({
      infoData: data.data
    })
  },
  async refundApply() {
    if (this.data.infoData.status != -1) {
      wx.showModal({
        title: '',
        content: '是否确认退款，退款成功后店铺将会被关闭',
        complete: async (res) => {
          if (res.confirm) {
            let {
              data
            } = await app._postNetWork({
              url: app.getNetAddresss("plugin.agent-shop.frontend.apply.refundApply"),
            })
            app.tips(data.msg);
            this.getData();
          }
        }
      })
    }
  },
  async getGood() {
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.agent-shop.frontend.goods.searchGoods"),
    })
    if (!data.result) return app.tips(data.msg);
    console.log(data)
    this.setData({
      goodsList: data.data.data,
      total_page: data.data.last_page,
      isLoadMore: true
    })
  },
  async getPoster() {
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.agent-shop.frontend.agent.getPoster"),
      data: {
        id: this.data.infoData.id
      }
    })
    if (!data.result) return app.tips(data.msg);
    this.setData({
      defaultImg: data.data.url,
      posterShow: true
    })
  }
})